package handin06;

/**
 * Coin is the super class of the concrete coins.
 * @author Peter Tolstrup Aagesen, ptaa@itu.dk
 *
 */
public class Coin implements Valuable {
	
	//value
	private double coinValue;
	
	//type
	private CoinType coinType;
	
	/**
	 * Coin constructor
	 * @param value double
	 * @param type CoinType
	 */
	public Coin(double value, CoinType type)
	{
		//Set instance variables
		coinValue = value;
		coinType = type;
	}
	
	/**
	 * getValue returns the value of the coin
	 * @return double
	 */
	public double getValue()
	{
		//Return
		return coinValue;
	}
	
	/**
	 * getType returns the coin type
	 * @return CoinType
	 */
	public CoinType getType()
	{
		//Return
		return coinType;
	}
	
	/**
	 * toString returns a String describing the state of the Coin
	 */
	public String toString()
	{		
		//Format coin type String
		String type = coinType.toString().substring(0, 1) + coinType.toString().substring(1).toLowerCase();
		
		//Return 
		return "This is a " + type + " Coin worth " + coinValue;
	}
	
	@Override
	public boolean equals(Object c) {
		boolean returnValue = false;
		if(this == c){
			returnValue = true;
		} else if(c instanceof Coin){
			Coin other = (Coin) c;
			if(other.getType() == this.coinType && other.getValue() == this.coinValue)
			{
				returnValue = true;				
			}
		}
		return returnValue;
	}
}
